package cn.wyl.system.controller;

import cn.wyl.basic.util.AxiousResult;
import cn.wyl.basic.util.PageList;
import cn.wyl.system.domain.Systemdictionarytype;
import cn.wyl.system.query.SystemdictionarytypeQuery;
import cn.wyl.system.service.SystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接口类：员工
 */
@RestController
@RequestMapping("/systemdictionarytype")
@Api(value = "员工接口",description = "员工接口")
public class SystemdictionarytypeController {

    @Autowired
    private SystemdictionarytypeService systemdictionarytypeService;

    /**
     * 接口：查询单个对象
     * @param id
     * @return
     */
    //http://localhost:8080/systemdictionarytype/1 + get
    @ApiOperation(value = "查询单个对象")
    @GetMapping("/{id}")
    public Systemdictionarytype findOne(@PathVariable("id")Long id){
        return systemdictionarytypeService.loadById(id);
    }

    /**
     * 接口：查询所有对象
     * @return
     */
    //http://localhost:8080/systemdictionarytype + 无 + get
    @ApiOperation(value = "查询所有对象")
    @GetMapping
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.loadAll();
    }

    /**
     * 接口：分页查询
     * @param query
     * @return
     */
    //http://localhost:8080/systemdictionarytype + {json对象} + post
    @ApiOperation(value = "分页查询")
    @PostMapping
    public PageList<Systemdictionarytype> queryPage(@RequestBody SystemdictionarytypeQuery query){
        return systemdictionarytypeService.queryPage(query);
    }

    /**
     * 接口：删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    //http://localhost:8080/systemdictionarytype/1 + delete
    public AxiousResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarytypeService.remove(id);
            return new AxiousResult();//true + "操作成功"
        } catch (Exception e) {
            e.printStackTrace();
            return new AxiousResult(false,"删除失败");
            //return AjaxResult.me().setSuccess(false).setMessage("删除失败");
        }
    }

    /**
     * 接口：添加或修改
     * @param systemdictionarytype
     * @return
     */
    @ApiOperation(value = "添加或修改")
    //http://localhost:8080/systemdictionarytype + {json对象} + put
    @PutMapping
    public AxiousResult addOrUpdate(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if(systemdictionarytype.getId() == null){//添加
                systemdictionarytypeService.save(systemdictionarytype);
            }else{
                systemdictionarytypeService.update(systemdictionarytype);
            }
            return new AxiousResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AxiousResult(false,"操作失败");
        }
    }



    /**
     * 接口：批量删除
     * @param
     * @return
     */
    @PatchMapping
    @ApiOperation(value = "批量删除")
    //前端传递的是数组 - 后端既可以用数组,也可以用集合
    public AxiousResult patchDelete(@RequestBody List<Long> ids){
        try {
            systemdictionarytypeService.patchDel(ids);
            return new AxiousResult();//true + "操作成功"
        } catch (Exception e) {
            e.printStackTrace();
            return new AxiousResult(false,"删除失败");
        }
    }


}